package com.hw.core.config;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import java.util.Properties;

@Configuration
@EnableCaching//开启缓存
@EnableScheduling//开启定时任务
@EnableElasticsearchRepositories(basePackages = "com.hw.core.system.esRepository")
@EnableJpaRepositories(basePackages = {"com.hw.core.system.repository"})
public class WebConfig {
    @Bean(name = "simpleMappingExceptionResolver")
    public SimpleMappingExceptionResolver createSimpleMappingExceptionResolver() {
        SimpleMappingExceptionResolver r = new SimpleMappingExceptionResolver();
        Properties mappings = new Properties();
        mappings.setProperty( "UnauthorizedException", "unauthorized" );  //捕捉权限异常跳转403页面
        mappings.setProperty( "Exception", "exception" );//出现其它的异常跳转到exception页面
        r.setExceptionMappings( mappings );
        r.setDefaultErrorView( "error" );    // 定义默认的异常处理页面，当该没有注册对应的异常类型处理时使用。
        r.setExceptionAttribute( "exception" );//页面上获取异常信息变量名
        return r;
    }
}
